package org.example.xuleihuaiol;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Text02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        test();
        test2();
    }
    public static Student getStudent(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("学生学号：");
        Integer id = scanner.nextInt();
        System.out.println("学生姓名：");
        String name =scanner.next();
        System.out.println("学生年龄：");
        Integer age = scanner.nextInt();
        return new Student(id,name,age);
    }
    public static void test() throws IOException {
        //定义list集合，存储学生数据
        ArrayList<Object> list = new ArrayList<>();
        list.add(getStudent());
        list.add(getStudent());
        list.add(getStudent());
        //序列化list
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:/IDEA-file/list.txt"));
        oos.writeObject(list);
        oos.flush();
        oos.close();
    }
    public static void test2() throws IOException, ClassNotFoundException {
        //反序列化
        ObjectInputStream ois =new ObjectInputStream(new FileInputStream("E:/IDEA-file/list.txt"));
        ArrayList<Student> o = (ArrayList<Student>) ois.readObject();
        System.out.println("反序列化list:"+o);
    }
}
